#ifndef _HDL_FLASH_H_
#define _HDL_FLASH_H_

#include "bsp.h"


#define FLASH_SPI_SPIx              SPI1
#define FLASH_SPI_APBxClock_FUN     RCC_APB2PeriphClockCmd
#define FLASH_SPI_CLK               RCC_APB2Periph_SPI1

#define FLASH_SPI_GPIO_APBxClock_FUN    RCC_APB2PeriphClockCmd
#define FLASH_SPI_GPIO_CLK          RCC_APB2Periph_GPIOA
#define FLASH_SPI_GPIO_PORT         GPIOA
#define FLASH_SPI_GPIO_NSS          GPIO_Pin_4
#define FLASH_SPI_GPIO_SLK          GPIO_Pin_5
#define FLASH_SPI_GPIO_MISO         GPIO_Pin_6
#define FLASH_SPI_GPIO_MOSI         GPIO_Pin_7
//////////////////////////////////////////////////////////////////////
#define FLASH_SPI_CS_HIGH           GPIO_SetBits(FLASH_SPI_GPIO_PORT,FLASH_SPI_GPIO_NSS)
#define FLASH_SPI_CS_LOW            GPIO_ResetBits(FLASH_SPI_GPIO_PORT,FLASH_SPI_GPIO_NSS)

#define FLASH_JEDEC_ID              0xef4018
#define FLASH_PageSize              256

typedef enum _hdl_flash_w25x_cmd
{
    FLASH_CMD_Dummy = 0x00,
    FLASH_CMD_W25X_WriteStatusReg = 0x01,
    FLASH_CMD_W25X_PageProgram = 0x02,
    FLASH_CMD_W25X_ReadData = 0x03,
    FLASH_CMD_W25X_WriteDisable = 0x04,
    FLASH_CMD_W25X_ReadStatusReg = 0x05,
    FLASH_CMD_W25X_WriteEnable = 0x06,
    FLASH_CMD_W25X_FastReadData = 0x0B,
    FLASH_CMD_W25X_SectorErase = 0x20,
    FLASH_CMD_W25X_FastReadDual = 0x3B,
    FLASH_CMD_W25X_ManufactDeviceID = 0x90,
    FLASH_CMD_W25X_JedecDeviceID = 0x9F,
    FLASH_CMD_W25X_ReleasePowerDown = 0xAB,
    FLASH_CMD_W25X_PowerDown = 0xB9,
    FLASH_CMD_W25X_ChipErase = 0xC7,
    FLASH_CMD_W25X_BlockErase = 0xD8,
}HDL_FLASH_W25X_CMD;

void hdl_flash_init(void);
#endif
